<?php
namespace App\Http\Controllers\Dashboard;


use Illuminate\Http\JsonResponse;
use Illuminate\Http\UploadedFile;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class ImageController extends BaseController
{


    /**
     * 上传文件
     *
     * @param Request $request
     * @return JsonResponse
     */
    public  function upload(Request $request) {

        /* @var UploadedFile $file  */
        $file = $request->file('file');

        $path = Storage::disk('public')->putFileAs(
            sprintf('%s', date("Ymd")),
            $file,
            sprintf("%s.%s", md5($file->getFilename() . rand()), $file->guessExtension())
        );

        return response()->json([
            'code' => 0,
            'msg' => '上传成功',
            'data' => Storage::disk('public')->url($path)
        ]);
    }

}
